<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserOauthTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_oauth', function (Blueprint $table) {
            /*字段配置--begin*/
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('所属会员');
            $table->string('wechat_open_id')->default('');
            $table->string('wechat_union_id')->default('');
            $table->string('dt_open_id')->default('');
            $table->timestamps();
            /*字段配置--end*/

            /*索引配置--begin*/
            $table->unique('user_id');
            # TODO 后续的openid以及unionid都应该加上唯一索引
            /*索引配置--end*/

            /*基础配置--begin*/
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            /*基础配置--begin*/
        });
        // 给表添加注释
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `user_oauth` comment'用户第三方登录表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_oauth');
    }
}
